var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userVo: {}, //个人资料信息
    userId: '',
    auditStatusText: '', //auditStatus:1未认证2认证失败3认证成功
    wxType: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    that.setData({ wxType: app.globalData.wxType });
  },
  onShow() {
    this.onMineInfo();
  },
  onMineInfo: function() {
    wx.showLoading({ title: '加载中' });
    var that = this;
    wx.request({
      method: 'POST',
      url: app.preUrl + 'findByUserId',
      dataType: 'json',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        userId: app.globalData.userId
      },
      success: function(res) {
        wx.hideLoading();
        if (res.data.code == 100) {
          that.setData({
            userVo: res.data.result
          });
          if (res.data.result.auditStatus == 1) {
            that.setData({
              auditStatusText: '未认证'
            });
          } else if (res.data.result.auditStatus == 2) {
            that.setData({
              auditStatusText: '认证失败'
            });
          } else if (res.data.result.auditStatus == 3) {
            that.setData({
              auditStatusText: '认证成功'
            });
          }
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.message,
            confirmColor: '#56BDE0',
            showCancel: false
          });
        }
      },
      fail: function(error) {
        console.log(error);
      }
    });
  },

  //个人设置中心
  goSetting: function() {
    wx.navigateTo({
      url: 'accountSetting'
    });
  },

  //我的余额
  goMyBalance: function() {
    var that = this;
    wx.navigateTo({
      url: 'myBalance'
    });
  },

  //意见反馈
  goSuggestion: function() {
    wx.navigateTo({
      url: 'suggestion'
    });
  },

  //销货订单
  goSalersOrder: function() {
    wx.navigateTo({
      url: 'salersOrder'
    });
  },

  //品类设置
  goCategorySetting: function() {
    wx.navigateTo({
      url: 'categorySetting'
    });
  },

  //账户设置
  goAccountSetting: function() {
    var that = this;
    wx.navigateTo({
      // url: 'accountSetting?contacts=' + that.data.userVo.contacts + '&telephone=' + that.data.userVo.telephone + '&detailAddress=' + detailAddress,
      url: 'accountSetting?contacts',
      success: function(res) {},
      fail: function(res) {},
      complete: function(res) {}
    });
  },

  gosupplyAndDemand: function() {
    wx.navigateTo({
      url: 'supplyAndDemand'
    });
  },
  callPhone() {
    wx.makePhoneCall({ phoneNumber: '0512-67229422' }); // 仅为示例，并非真实的电话号码
  },
  //我的银行卡页面
  goBindBandCard: function() {
    var that = this;
    var wxType = that.data.userVo.wxType;
    var phone = that.data.userVo.telephone;
    // if (that.data.userVo.auditStatus != 3) {
    //   wx.showModal({
    //     title: '身份认证成功才能设置支付密码',
    //     confirmColor: '#56BDE0',
    //     showCancel: false,
    //   });
    //   wx.navigateTo({
    //     url: 'authentication'
    //   })
    // }else{
    //   var cardName = that.data.userVo.cardName;
    //   var cardNum = that.data.userVo.cardNum;
    //   wx.navigateTo({
    //     url: 'bindBandCard?cardName=' + cardName + '&cardNum=' + cardNum,
    //   })
    // }
    wx.navigateTo({
      url: 'myBandCard'
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target);
    }
    return {
      title: '绿大侠',
      imageUrl: '/pages/images/share_bg.png',
      path: '/pages/home/home?userId=' + app.globalData.userId
    };
  },
  //退出当前账号
  tuichu() {
    wx.removeStorage({
      key: 'userId',
      success(res) {
        console.log(res);
      }
    });
    wx.removeStorage({
      key: 'map_Location',
      success(res) {
        console.log(res);
      }
    });
    wx.reLaunch({
      url: '/pages/registerOrLogin/login'
    });
  }
});
